package com.db.diary;

import java.io.Reader;
import java.sql.SQLException;
import java.util.List;

import com.db.diary.*;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

public class DiaryManager{
	private static SqlMapClient sqlmap;
	static {
		try {
			Reader reader = Resources
					.getResourceAsReader("com/db/config/SqlMapConfig.xml");
			sqlmap = SqlMapClientBuilder.buildSqlMapClient(reader);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
	
	public static List diaryMonthData(DiaryListVO lvo) throws SQLException{
		return sqlmap.queryForList("diaryMonthData", lvo);
	}
	
	public static void diaryInsert(DiaryVO vo) throws SQLException{
		sqlmap.insert("diaryInsert", vo);
	}
	
	public static int diarySeq() throws SQLException{
		return (Integer)sqlmap.queryForObject("diarySeq");
	}
	
	public static void diaryDetailInsert(DiaryDetailVO dvo) throws SQLException{
		sqlmap.insert("diaryDetailInsert", dvo);
	}
	
	public static DiaryListVO getDiaryDetailContent(DiaryListVO lvo) throws SQLException{		
		return (DiaryListVO)sqlmap.queryForObject("getDiaryDetailContent", lvo);
	}
	
	public static List getMainDiaryList(int memno) throws SQLException{
		return sqlmap.queryForList("getMainDiaryList", memno);
	}
	
	public static void diaryDelete(int diary_num) throws SQLException{
		sqlmap.update("diaryDelete", diary_num);
	}
	
	public static void diaryDetailUpdate(DiaryDetailUpdateVO duvo) throws SQLException{
		sqlmap.update("diaryDetailUpdate", duvo);
	}
	
	public static void diaryUpdate(DiaryVO vo) throws SQLException{
		sqlmap.update("diaryUpdate", vo);
	}
	
	public static void diaryDetailDelete(int diary_num) throws SQLException{
		sqlmap.delete("diaryDetailDelete", diary_num);
	}
	
	//public static DiaryVO getDiaryRepeatInfo(int diary_num) throws SQLException{
//		return (DiaryVO)sqlmap.queryForObject("getDiaryRepeatInfo", diary_num);
//	}
}
